package com.qf.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsRoleMapper;
import com.qf.pojo.DtsRole;
import com.qf.service.AdminRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;


@Service
public class AdminRoleServiceImpl implements AdminRoleService {

    @Autowired
    private DtsRoleMapper dtsRoleMapper;

    @Override
    public Page<DtsRole> selectRoleList(Integer page, Integer limit, String sort, String order, String rolename) {

        Page<DtsRole> ipage = new Page<>(page, limit);

        QueryWrapper<DtsRole> wrapper = new QueryWrapper<>();
        wrapper.eq("deleted", false);
        wrapper.like(!StringUtils.isEmpty(rolename), "`name`", rolename);
        wrapper.orderByAsc("asc".equalsIgnoreCase(order),sort);
        wrapper.orderByDesc("desc".equalsIgnoreCase(order),sort);
        Page<DtsRole> dtsRolePage = dtsRoleMapper.selectPage(ipage, wrapper);

        return dtsRolePage;
    }

    @Override
    public List<DtsRole> selectRoleOptions() {


        QueryWrapper<DtsRole> wrapper = new QueryWrapper<>();
        wrapper.select("id,name")
                .eq("deleted", false);
        List<DtsRole> dtsRoles = dtsRoleMapper.selectList(wrapper);
        return dtsRoles;
    }
}
